﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Guru.Utilities
{
    public static class Formatter
    {
        public static string FormatPhone(this object phone)
        {
            string phoneNumber = phone as string;
            if (string.IsNullOrEmpty(phoneNumber)) return string.Empty;
            else if (phoneNumber.Length == 10)
                return string.Format("({0}) {1} {2}", phoneNumber.Substring(0, 4), phoneNumber.Substring(4, 3), phoneNumber.Substring(7, 3));
            else if (phoneNumber.Length == 11)
                return string.Format("({0}) {1} {2}", phoneNumber.Substring(0, 5), phoneNumber.Substring(5, 3), phoneNumber.Substring(8, 3));
            return phoneNumber;
        }
        public static string FormatCurrency(this object value, string languageID)
        {
            if (value == null || value == DBNull.Value) value = 0;
            switch (languageID.ToUpper().Trim())
            { 
                case "VN":
                    string formated = String.Format("{0:#,0}", Convert.ToInt64(value));
                    return String.Format("{0}", formated);
                case "US":
                    return String.Format("{0:C}", value);
            }
            return value.ToString();
        }
        public static string FormatCurrency(this object value)
        {
            return FormatCurrency(value, "VN");
        }
        public static string FormatDate(this object date)
        {
            if (date == null || date == DBNull.Value) return string.Empty;
            DateTime dt = Convert.ToDateTime(date);
            return dt.ToString("dd/MM/yyyy");
        }
        public static string FormatDateTime(this object date)
        {
            if (date == null || date == DBNull.Value) return string.Empty;
            DateTime dt = Convert.ToDateTime(date);
            return dt.ToString("dd/MM/yyyy HH:mm");
        }
    }
}
